<template>
  <div>
    <!--<HeaderCustom :title="headtitle"/>-->
    <!--<mt-header class="bgcolor" :title="headtitle">-->
      <!--<router-link :to="{ name: 'MyRelease2', params: { url:'/' ,filterParams:params.filterParams}}" slot="left">-->
        <!--<mt-button icon="back">返回</mt-button>-->
      <!--</router-link>-->
      <!--<mt-button slot="right" @click="goback">back</mt-button>-->
    <!--</mt-header>-->
    <!--<HeaderCustom :title="headtitle"/>-->
    <!--<HeaderToLast :title="headtitle" v-on:delWholeInfo="delWholeInfo"/>-->
    <MainInfo class="" :maininfo="flyInfoMain"/>
    <el-card class="box-card info-color">
      <el-collapse v-model="activeNames" @change="handleChange">
        <el-collapse-item v-for=" (item, index)  in detailList" :title="items[index].title" :name="items[index].name"
                          :key="index">
          <InfoDetail class="row" :item="item"/>
          <div class="row" v-if="isReleasePage">
            <!--<mt-button @click="editinfo(item)" >编辑</mt-button>-->
            <mt-button @click="delinfo(item,index)">删除</mt-button>

          </div>
        </el-collapse-item>
      </el-collapse>
    </el-card>
  </div>

</template>

<script>
  import {
    Indicator,
    Toast,
    MessageBox
  } from 'mint-ui'
  import MainInfo from './MainInfo'
  import TimeLine from './TimeLine'
  import Header from './Header'
  import InfoDetail from './InfoDetail'
  import HeaderToLast from './HeaderToLast'
  import HeaderCustom from './HeaderCustom'
  import Global from './Global'
  import axios from 'axios'
  export default {
    name: 'DetailInfoPage',
    // props:['list'],
    components: {HeaderCustom, HeaderToLast, InfoDetail, Header, TimeLine, MainInfo},
    data () {
      return {
        headtitle: '信息详情',
        isReleasePage:true,
        maininfo: {},
        flyInfoMain: {},
        detailList: [],
        activeNames: ['1'],
        items: [],
        params: {},
        url: ''
      }
    },
    methods: {
      goback () {
        this.$router.go(-1)
      },
      editinfo (item) {
        console.log('editinfo')
        this.$router.push({name:'EditInfoPage',params:{item:item}})

      },
      delinfo (item,index) {
        console.log('delinfo')
        let that=this
        axios.delete(Global.serverSrc + '/fly/info/detail/one',  {data: item})
          .then(function (res) {
            console.log(res)

            if (res.data.code === 0) {
              Toast({
                message: '表单提交成功',
                position: 'bottom'
              })
              that.detailList.splice(index,1)
            }else{
              Toast({
                message: '表单提交失败',
                position: 'bottom'
              })
            }


            // this.$router.go(-1)
          })
          .catch(function (err) {
            console.log(err)
            Indicator.close()
            Toast({
              message: '表单提交失败',
              position: 'bottom'
            })
          })
      },
      delWholeInfo () {
        this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
          center: true
        }).then(() => {
          console.log('删除')

          axios.post(Global.serverSrc + '/fly/info/create/batch', {
            flyInfoMain: mainData,
            flyInfoDetailList: addList
          })
            .then(function (res) {
              console.log(res)
              Indicator.close()

              Toast({
                message: '表单提交成功',
                position: 'bottom'
              })
              this.$router.go(-1)
            })
            .catch(function (err) {
              console.log(err)
              Indicator.close()
              Toast({
                message: '表单提交失败',
                position: 'bottom'
              })
            })
        }).catch(() => {

        })
      },
      handleChange (val) {
        console.log(val)
      }
    },
    created () {
      this.url = this.$route.params.url
      this.params = {}
      this.params.userid = this.$store.state.userid
      this.params.filterParams = this.$route.params.filterParams

      if (this.url !== '/userPublish/') {
        this.isReleasePage=false
      }



      console.log(this.$route.params.datas)
      this.detailList = this.$route.params.datas.flyInfoDetailList
      this.flyInfoMain = this.$route.params.datas.flyInfoMain

      if (!this.detailList) {
        this.detailList = this.$store.state.detailData
      } else {
        this.$store.commit("updateDetailData",this.detailList)
      }
      if (!this.flyInfoMain) {
        this.flyInfoMain = this.$store.state.detailDataflyInfoMain
      } else {
        this.$store.commit("updateDetailDataflyInfoMain",this.flyInfoMain)
      }

      for (let i = 0; i < this.detailList.length; i++) {
        var item = {}
        item.name = i + 1 + ''
        item.title = '架次' + (i + 1)
        this.items.push(item)
      }
    }
  }
</script>

<style scoped>
  .fix-bottom {
    margin: 0 auto;
    display: block;
    width: 98%;
    position: fixed;
    bottom: 0;
  }

  .row {
    text-align: left;
  }

</style>
